var KEY = {};

KEY.init = function(){
	var annList = $jq('.announcements-list');
		annList.children('li').find('h3').on('click', function(e){
		e.preventDefault();
		$jq(this)
		.toggleClass('active')
		.siblings('.partial').toggle()
		.siblings('.full').toggle();
	});
		
		$jq(document).on('click', '.cat_title', function(e){
			$jq(this).closest('li').toggleClass('active')
			.find('.cat_body_wrapper').slideToggle();
		});
	
	var crfaqList = $jq('.cr-faq-list');
		crfaqList.find('.cr-faq-question').on('click', function(){
		$jq(this)
		.toggleClass('active')
		.closest('li').find('.cr-faq-answer').slideToggle();
	});	

    var parentList = $jq('#faq-full-list');
		parentList.find('.faq-question').on('click', function(){
		$jq(this)
		.toggleClass('active')
		.closest('li').find('.faq-answer').slideToggle();
	});
	
	$jq('.announcements-list .views-more-link').click(function(e){
		e.preventDefault();
		$jq(this).closest('li').find('h3').trigger('click');
	});
	$jq('.announcements-list .dcless').click(function(e){
		e.preventDefault();
		$jq(this).closest('li').find('h3').trigger('click');
	});
    
    $jq('.fancybox').fancybox({type:'iframe'});
    
    $jq("select").minimalect();
    
    $jq('.call-today').click(function(e){
	    e.preventDefault();
    });

    //$jq(".views-exposed-form").find(".form-submit").addClass('red-button');
    
};


KEY.detectMegaMenu = function(){

	var bigParent = $jq('#hs_nav');
	var rightMenu = bigParent.find('.content').children('ul.right');
	
	rightMenu.children('li').each(function(el){
		var par = $jq(this);
		var sub = par.children('ul');
		if(sub.length > 0)
		{	
			sub.removeClass('right');
			var second = sub.clone();
			par.removeClass('expanded').addClass('has-dropdown');
			sub.addClass('dropdown');
			sub.children('li.menu-views').remove();
			sub.children('li.menu-views-right').remove();
			second.addClass('dropdown');
			par.append(second);
			second.wrap('<div class="dropdown"><div class="row"><div class="small-2 menu columns"></div></div></div>');
			var mega = second.closest('.row');
			var mvli = second.children('li.menu-views').eq(0).detach();
			var mvli2 = second.children('li.menu-views').eq(0).detach();
			var mv = mvli.find('.view-content');
			var mv2 = mvli2.find('.view-content');
			if(mv.length > 0)
			{
				mega.append(mv);
				mv.wrap('<div class="small-8 columns megamenu">');	
				if(mv2.length > 0)
				{
					mv2.insertAfter(mv);	
				}
			}
			
		}
	});
	bigParent.show();
	
};

KEY.initTopBar = function()
{
	var evt = 'click.fndtn.topbar',
        sel = '.top-bar .toggle-topbar, [data-topbar] .toggle-topbar';
    $jq(document)
      .off(evt, sel)
      .on(evt, sel, function(e){
        //var topbar = $jq('.top-bar, [data-topbar]'),
        var topbar = $jq(this).closest('nav');
        section = topbar.find('section, .section');

        if (Foundation.libs.topbar.breakpoint()) {
          if (!self.rtl) {
            section.css({left: '0%'});
            section.find('>.name').css({left: '100%'});
          } else {
            section.css({right: '0%'});
            section.find('>.name').css({right: '100%'});
          }

          section.find('li.moved').removeClass('moved');
          topbar.data('index', 0);

          topbar
            .toggleClass('expanded')
            .css('height', '');
        }

        if(Foundation.libs.topbar.settings.scrolltop)
        {
          if (!topbar.hasClass('expanded')) {
            if (topbar.hasClass('fixed')) {
              topbar.parent().addClass('fixed');
              topbar.removeClass('fixed');
              $jq('body').addClass('f-topbar-fixed');
            }
          } else if (topbar.parent().hasClass('fixed')) {
            if (self.settings.scrolltop) {
              topbar.parent().removeClass('fixed');
              topbar.addClass('fixed');
              $jq('body').removeClass('f-topbar-fixed');

              window.scrollTo(0,0);
            } else {
                topbar.parent().removeClass('expanded');
            }
          }
        } else {
          if(topbar.parent().hasClass(self.settings.stickyClass)) {
            topbar.parent().addClass('fixed');
          }

          if(topbar.parent().hasClass('fixed')) {
            if (!topbar.hasClass('expanded')) {
              topbar.removeClass('fixed');
              topbar.parent().removeClass('expanded');
              self.updateStickyPositioning();
            } else {
              topbar.addClass('fixed');
              topbar.parent().addClass('expanded');
            }
          }
        }
      });
}

KEY.initFacultyAccordion = function()
{
	var parentList = $jq('#faculty-staff-full-list');
		parentList.find('.view-header').on('click', function(){
		$jq(this)
		.toggleClass('active')
		.siblings('.view-content').slideToggle();
	});
}


$jq(document).ready(function(){
   KEY.init();
   KEY.detectMegaMenu();
   $jq(this).foundation();
   KEY.initTopBar();
   KEY.initFacultyAccordion();

  $jq('.carrot').click(function(){
     $jq('.carrot-show').slideUp('fast');
     $jq('.carrot-wrapper').slideDown('fast');
      $jq(this).parent('.carrot-wrapper').slideUp('fast');
      $jq(this).closest('li').find('.carrot-show').slideDown('fast');

  });
});
